package com.briup.mt.service.impl;

import com.briup.mt.bean.BaseConfig;
import com.briup.mt.bean.BaseConfigExample;
import com.briup.mt.dao.BaseConfigMapper;
import com.briup.mt.service.IBaseConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class BaseConfigServiceImpl implements IBaseConfigService {

    @Autowired
    private BaseConfigMapper baseConfigMapper;

    @Override
    public List<BaseConfig> query(String name, String val) {
        BaseConfigExample example=new BaseConfigExample();
        if (!StringUtils.isEmpty(name)){
            example.createCriteria().andNameLike("%"+name+"%");
        }
        if (!StringUtils.isEmpty(val)){
            example.createCriteria().andValEqualTo(val);
        }

        List<BaseConfig> list = baseConfigMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(BaseConfig baseConfig) {

        if (baseConfig.getId()==null){
            baseConfigMapper.insert(baseConfig);
        }else {
            baseConfigMapper.updateByPrimaryKey(baseConfig);
        }
    }

    @Override
    public void deleteById(long id) {
        baseConfigMapper.deleteByPrimaryKey(id);

    }
}
